package rdd.transform

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Spark01_RDD_GroupBy2 {
  def main(args: Array[String]): Unit = {
    val sparkConf: SparkConf = new SparkConf().setMaster("local[*]").setAppName("RDD")
    val sc = new SparkContext(sparkConf)
    val rdd: RDD[String] = sc.makeRDD(List("hello","spark","Scala","hadoop"), 2)
    //groupBy将数据源中的每一个数据进行分组判断，根据返回的分组key进行分组，相同的key会放在一个组中
    val groupByRDD: RDD[(Char, Iterable[String])] = rdd.groupBy(
      (str:String) => {
        str.charAt(0)
      }
    )
    //分组和分区没有必然关系
    groupByRDD.collect().foreach(println)
    sc.stop()
  }

}
